home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / finances / sheet30d / dbman.txt < prev    next >
Encoding:
Text File  |  1995-04-25  |  41.3 KB  |  1,057 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.                                SHEET version 3.0
  27.  
  28.                             Manual of Database Part
  29.  
  30.                                By Chor-ming Lung
  31.  
  32.                             Date: November 1, 1989
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.                                Table of contents
  78.                                _________________
  79.  
  80.  
  81.      Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . .   1
  82.  
  83.      Database creation  . . . . . . . . . . . . . . . . . . . . . . . .   1
  84.  
  85.      Criteria range . . . . . . . . . . . . . . . . . . . . . . . . . .   2
  86.           Criteria  . . . . . . . . . . . . . . . . . . . . . . . . . .   2
  87.                Comparison criteria  . . . . . . . . . . . . . . . . . .   2
  88.                Match criteria . . . . . . . . . . . . . . . . . . . . .   2
  89.                Computed criteria  . . . . . . . . . . . . . . . . . . .   2
  90.           Combining criteria  . . . . . . . . . . . . . . . . . . . . .   2
  91.  
  92.      Database operations  . . . . . . . . . . . . . . . . . . . . . . .   3
  93.           Set Database  . . . . . . . . . . . . . . . . . . . . . . . .   3
  94.           Set Criteria range  . . . . . . . . . . . . . . . . . . . . .   3
  95.           Find  . . . . . . . . . . . . . . . . . . . . . . . . . . . .   3
  96.           Extract . . . . . . . . . . . . . . . . . . . . . . . . . . .   3
  97.           Set Output range  . . . . . . . . . . . . . . . . . . . . . .   5
  98.           Delete  . . . . . . . . . . . . . . . . . . . . . . . . . . .   5
  99.  
  100.      Database functions . . . . . . . . . . . . . . . . . . . . . . . .   6
  101.           DSUM, DCOUNT, DAVERAGE, DMIN, DMAX, DSTD, DVAR  . . . . . . .   6
  102.  
  103.      Database commands  . . . . . . . . . . . . . . . . . . . . . . . .   7
  104.           QUERY . . . . . . . . . . . . . . . . . . . . . . . . . . . .   7
  105.           EXTRACT . . . . . . . . . . . . . . . . . . . . . . . . . . .   7
  106.           DB_INPUT 
  107.           DB_INPUT  . . . . . . . . . . . . . . . . . . . . . . . . . .   7
  108.                Input record . . . . . . . . . . . . . . . . . . . . . .   8
  109.                     Query . . . . . . . . . . . . . . . . . . . . . . .   8
  110.                     Search  . . . . . . . . . . . . . . . . . . . . . .   8
  111.                     Next  . . . . . . . . . . . . . . . . . . . . . . .   8
  112.                Query forms  . . . . . . . . . . . . . . . . . . . . . .  10
  113.                Find records . . . . . . . . . . . . . . . . . . . . . .  10
  114.                DB_INPUT arguments . . . . . . . . . . . . . . . . . . .  10
  115.                     Database  . . . . . . . . . . . . . . . . . . . . .  10
  116.                     Display . . . . . . . . . . . . . . . . . . . . . .  10
  117.                     Query . . . . . . . . . . . . . . . . . . . . . . .  11
  118.                     Relation list . . . . . . . . . . . . . . . . . . .  11
  119.                DB_INPUT entry . . . . . . . . . . . . . . . . . . . . .  11
  120.           BUTTON  . . . . . . . . . . . . . . . . . . . . . . . . . . .  12
  121.           CUR_REC . . . . . . . . . . . . . . . . . . . . . . . . . . .  12
  122.  
  123.      Phone Book II  . . . . . . . . . . . . . . . . . . . . . . . . . .  13
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  SHEET -- Database Part        By Chor-ming Lung               November 1, 1989
  146.  
  147.  
  148.                               Database management
  149.                               ___________________
  150.                                                  
  151.  
  152.      Introduction:
  153.      ____________
  154.           SHEET v3.0  provides database  functions and operations which are
  155.      quite similar to Lotus 123. If  you  are  familiar  with  the database
  156.      manager of  Lotus 123, feel free to jump to the part starting from the
  157.      discussion of DB_INPUT.
  158.                    DB_INPUT
  159.  
  160.           We will use an  address book  and a  small personnel  database as
  161.      examples  to  guide  you  through  different  aspects  of the database
  162.      manager of SHEET.
  163.  
  164.           First of  all, we  will discuss  the creation  of database. After
  165.      that, we  will discuss about searching criteria and combining criteria
  166.      to form criteria range for manipulating information from  the database
  167.      (creating  queries  and  using  database  functions/opertions).  BASIC
  168.      database commands  are introduced.  Finally, we  will try  to write an
  169.      application to handle our address book.
  170.  
  171.      Database creation:
  172.      _________________
  173.           Before  you  enter  any  record,  we need to decide what elements
  174.      constitute the database we need. If we are  creating address  book, we
  175.      need to  store the  name of  the person, address and his phone number.
  176.      Those elements (name, address,  phone number)  are called  fields of a
  177.                                                                 fields
  178.      database. You  can refine  the field  NAME to First Name, Middle Name,
  179.                                            ____
  180.      Last Name  and ADDRESS  to Street,  City, State  and Zip  code. In our
  181.                     _______
  182.      address  book,  we  use  one  field  to  store names of persons we are
  183.      interested. The ADDRESS is splited as mentioned above.  Sure, it takes
  184.      up  more  columns  to  store  the  address  but  it  is easier to find
  185.      particular records. So, we  have the  following fields  in our address
  186.      book:
  187.                Name
  188.                ____      Street
  189.                          ______    City
  190.                                    ____      State
  191.                                              _____     Zip code
  192.                                                        ________
  193.  
  194.           The next  step in creating database is to find a place to put our
  195.      database. To simplify everything, we start the database  from cell A1.
  196.      The first row of a spreadsheet database stores the field names. So, we
  197.      enter Name in A1, Street in  B1  ....  We  have  some  data  stored in
  198.            ____        ______
  199.      FONBKII.SHT for our address book database.
  200.  
  201.  
  202.           Our  second  example  is  in  DATABASE.SHT.  It  is  a simplified
  203.      personnel database. It consists of the following fields:
  204.                Last Name
  205.                _________ 
  206.                               Date Hired
  207.                               __________     Age
  208.                                              ___  Sex
  209.                                                   ___  Salary
  210.                                                        ______
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.                                       D 1
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  SHEET -- Database Part        By Chor-ming Lung               November 1, 1989
  234.  
  235.  
  236.      Criteria range:
  237.      ______________
  238.           Once you have created  the database,  you can  locate, extract or
  239.      delete data from the database. To find the records desired, we need to
  240.      set up criteria to confine the search to  some special  group of data.
  241.      Spreadsheet database  manager uses  spatial structure to represent AND
  242.      and OR relationships between criteria. So, we need more than a cell to
  243.      define our  criteria. Those  cells which  hold our  criteria is called
  244.      criteria range.
  245.  
  246.           A criteria range is a special form of database. The  first row of
  247.      a criteria  range is  reserved for field names. The rest rows define a
  248.      set of criteria.  Criteria  on  each  row  will  be  AND  together and
  249.      criteria on different rows will be OR together. 
  250.  
  251.           Criteria:
  252.           ________
  253.                Comparison criteria:
  254.                Comparison criteria
  255.                     Only  numeric   values  can   be  compared.  Comparison
  256.                     operators >, <, <>,  >=, =>,  <=, =<  can all  be used.
  257.                     Here is an example of our two cells criteria:
  258.  
  259.                          Age
  260.                          ___
  261.                          >50
  262.  
  263.                     It means  from the  database, find  all persons who are
  264.                     over 50 years old.
  265.                Match criteria:
  266.                Match criteria
  267.                     Text string  can  be  searched  by  partial  match. For
  268.                     example:
  269.  
  270.                          Name
  271.                          ____
  272.                          an
  273.  
  274.                     It will  match names  like "Anita" or "Alan". The match
  275.                     is case-insensitive.
  276.                Computed criteria:
  277.                Computed criteria
  278.                     The field  name of  computed criteria  should be blank.
  279.                     The formula  on the  computed criteria consists of cell
  280.                     reference of the first  record. For  example, the first
  281.                     record  on  field  Age  is  on  cell  C2, the following
  282.                                        ___
  283.                     criteria find persons who are greater than 30  and less
  284.                     than 50.
  285.  
  286.                             
  287.                          ___
  288.                          +c2>30 and c2<50
  289.  
  290.           Combining criteria:
  291.           __________________
  292.                If you  are looking  for records which satisfy the following
  293.                condition on our personnel database:
  294.                     age>50 and sex is male OR age>40 and salary<30000
  295.  
  296.                the criteria range looks like this:
  297.                     Age
  298.                     ___  Sex
  299.                          ___  Salary
  300.                               ______
  301.                     >50  m
  302.  
  303.  
  304.                                       D 2
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  SHEET -- Database Part        By Chor-ming Lung               November 1, 1989
  315.  
  316.  
  317.                     >40       <30000
  318.           NOTE:
  319.           NOTE      If a criteria range  contains  a  blank  row,  then the
  320.                     whole database will meet the criteria.
  321.  
  322.  
  323.      Database operations:
  324.      ___________________
  325.  
  326.           Before we  go further,  we play with the file DATABASE.SHT to get
  327.      acquaintance with  the database  operations first  and understand what
  328.      they are later.
  329.  
  330.         - load the file DATABASE.SHT.
  331.         - move the mouse cursor over cell A1
  332.         - press <Control> key and then press the left mouse button
  333.         - move the mouse cursor over cell E11
  334.         - press <Shift> key and then press the left mouse button
  335.  
  336.      Mouse click with <Control> and <Shift> define a block containing cells
  337.      from A1 to E11. The block will be highlited by inverting to black.
  338.  
  339.         - move the mouse cursor  over the  menu title  Data and  select the
  340.                                                        Data
  341.           menu item Set Database.
  342.                     Set Database
  343.  
  344.      The highlited  block is  gone. It  means the database is designated to
  345.      cells A1..E11. If you want to  see the  designated area  again, select
  346.      the menu item Set Database.
  347.                    Set Database
  348.  
  349.         - select the menu item Set Criteria range.
  350.                                Set Criteria range
  351.  
  352.      The  block  A14..E15  will  be displayed. Well, the database, criteria
  353.      range and output range are pre-selected  and saved  with DATABASE.SHT.
  354.      The database  is A1..E11,  Criteria range  is A14..E15  and the Output
  355.      range is G1..J11.
  356.  
  357.           The criteria is:
  358.                     Age
  359.                     ___
  360.                     <30
  361.      It means we want to find persons whose ages are under 30. Well, select
  362.      the Find  menu item.  The record cursor is on the person name Holt. If
  363.          Find
  364.      you press the Down arrow key, the record cursor will move to  the girl
  365.      whose name  is Peacock.  If you  press the  Down arrow  key again, the
  366.      record cursor stays where  it is.  It means  no more  records meet the
  367.      criteria. NOTE:  the topmost line changes from Ready to Find. You must
  368.                NOTE                                 Ready    Find
  369.      click on any cell to change from Find mode to Ready.
  370.                                       Find         Ready
  371.  
  372.           Let us try to  extract records  to our  output range.  Select the
  373.      Extract menu  item. You  should see  that the data of Holt and Peacock
  374.      Extract
  375.      are copied to our output range. The information of Date Hire is not in
  376.      our output  range. That  is because  the first row confines the fields
  377.      being extracted.
  378.  
  379.           To experience more,  you  can  modify  the  criteria,  expand the
  380.      criteria range  and play  with it  again. But you should not save your
  381.  
  382.  
  383.                                       D 3
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  SHEET -- Database Part        By Chor-ming Lung               November 1, 1989
  394.  
  395.  
  396.      modified version of DATABASE.SHT. We will use it later.
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.                                       D 4
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  SHEET -- Database Part        By Chor-ming Lung               November 1, 1989
  462.  
  463.  
  464.  
  465.           Now, it is time to take a look of the  menu items  under the menu
  466.      title Data.
  467.            Data
  468.  
  469.           Set Database:
  470.           Set Database        Designate  the   current  block   to  be  the
  471.                               database being manipulated.  NOTE  a database
  472.                               includes the  field names and records. If you
  473.                               select  a  block  before  choosing  this menu
  474.                               item,  the  definition  of  the block will be
  475.                               inserted  into  Database  range  edit  field.
  476.                                               Database  range
  477.                               Otherwise, you have to enter it by yourself.
  478.           Set Criteria range:
  479.           Set Criteria range  Designate  the   current  block   to  be  the
  480.                               criteria  range.  A  criteria  range contains
  481.                               field names and criteria.
  482.           Set Output range:
  483.           Set Output range    Output range is used to designate an area for
  484.                               data extraction. The first row of  the output
  485.                               range  specifies  which fields being extract.
  486.                               See Extract for more detail.
  487.                                   Extract
  488.           Find:
  489.           Find                Use  the  criteria  defined  on  the criteria
  490.                               range   to   show   records  that  match  the
  491.                               criteria.  If  there  are  some  records that
  492.                               match the  criteria, then  the status will be
  493.                               changed from Ready to Find. If  you press the
  494.                                            Ready    Find
  495.                               arrow  key  Up/Down,  the  record cursor will
  496.                               move  to  the  next  record  that  meets  the
  497.                               criteria.  To  change  back from Find mode to
  498.                                                                Find
  499.                               Ready mode,  you  should  mouse-click  on any
  500.                               Ready
  501.                               cell.
  502.           Extract:
  503.           Extract             Extracts records which meet the criteria. The
  504.                               records will be stored in the area defined by
  505.                               Output  range.  NOTE:  Except  the first row,
  506.                                               NOTE
  507.                               Extract will erase  cells  within  the output
  508.                               range. If your output range has one row only,
  509.                               cells beneath this row and within the columns
  510.                               of output range will be erased. If you have 5
  511.                               records  that  meet  the  criteria,  but your
  512.                               output range  is only  4 rows big, only three
  513.                               records will be stored  in  the  output range
  514.                               (the first row contains field names).
  515.           Delete:
  516.           Delete              Deletes  records  that  meet the criteria. If
  517.                               deletion happens, your database range will be
  518.                               shorten.  Delete  affects  only  cells within
  519.                                         Delete
  520.                               database range.
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.                                       D 5
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  SHEET -- Database Part        By Chor-ming Lung               November 1, 1989
  544.  
  545.  
  546.      Database functions:
  547.      __________________
  548.           There are seven database functions built-in. They are:
  549.  
  550.                DSUM, DCOUNT, DAVERAGE, DMIN, DMAX, DSTD, DVAR
  551.                DSUM, DCOUNT, DAVERAGE, DMIN, DMAX, DSTD, DVAR
  552.  
  553.           Here is the syntax of our database functions:
  554.  
  555.                Dfun(database, index, criteria)
  556.                     database:
  557.                     database  it is the block which holds the data
  558.                     index:
  559.                     index     it can be an offset number or field name. The
  560.                               first field  has offset  of 1.  Salary on our
  561.                               DATABASE.SHT is  the fifth  field. Its offset
  562.                               number is  5. Instead  of using 5, we can use
  563.                               the field name "Salary" as the index.
  564.                     criteria:
  565.                     criteria  it is  the  block  which  holds  the criteria
  566.                               range.
  567.  
  568.           In our DATABASE.SHT, cell E13 has a formula:
  569.  
  570.                + DAVERAGE(A1..E11,"Salary",A14..E15)
  571.  
  572.      It means  we want to find the average of Salary from the records which
  573.      meet criteria A14..E15.
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.                                       D 6
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  SHEET -- Database Part        By Chor-ming Lung               November 1, 1989
  617.  
  618.  
  619.      Database commands:
  620.      _________________
  621.           There are four commands and one function in the BASIC interpreter
  622.      which relates with database manipulation. They are
  623.  
  624.                QUERY, EXTRACT, DB_INPUT, BUTTON and function CUR_REC
  625.                QUERY, EXTRACT, DB_INPUT, BUTTON              CUR_REC
  626.  
  627.           QUERY
  628.           QUERY
  629.                Syntax:
  630.                     QUERY database, criteria, cell
  631.  
  632.                database is the block which holds the data.
  633.                criteria is the block which holds the criteria range.
  634.                cell is  the  leading  cell  which we put the record numbers
  635.                     which meet the criteria. cell will  hold the  number of
  636.                                              cell
  637.                     records which  meet the  criteria. The cells below cell
  638.                                                                        cell
  639.                     will hold the actual record number. In our DATABASE.SHT
  640.                     file, if you run cell F12, you will see that cell k1 is
  641.                     2. It means we have 2 records meet the criteria.  K2 is
  642.                     1 and  K3 is  3. The actual records are record 1 (Holt)
  643.                     and record 3 (Peacock).
  644.  
  645.           EXTRACT
  646.           EXTRACT
  647.                Syntax:
  648.                     EXTRACT database, criteria_range, output_range
  649.  
  650.                It works similar to the Extract operation on the menu.
  651.                                        Extract
  652.  
  653.  
  654.           DB_INPUT
  655.           DB_INPUT
  656.                Syntax:
  657.                     DB_INPUT database, display, query, "relation list"
  658.  
  659.                It is possibly the most complex  command for  SHEET. For the
  660.                time being,  we will  go to  load the  DATABASE.SHT file and
  661.                have some hands-on experience first.
  662.  
  663.              - load the DATABASE.SHT file
  664.              - Press <Control> and P simultaneously
  665.              - Press <Return> to print our spreadsheet first
  666.              - Press <Shift> and left arrow key simultaneously
  667.              - move the mouse cursor over L11
  668.              - press <Alternate> and press the left mouse button to run the
  669.                single command program.
  670.  
  671.                A dialog  box similar  to a window shows up. If you click on
  672.           the close  box, the  dialog box  will be  closed and  it ends the
  673.           command DB_INPUT.
  674.  
  675.                Let us  take a closer look of the dialog box. Besides of the
  676.           close box, the title of the dialog box is Input record. There are
  677.                                                     Input record
  678.           9 boxes under the title. The first three of them are Query Search
  679.                                                                Query Search
  680.           and Next. The rest 6 boxes are empty. Below the boxes, we see the
  681.               Next
  682.           first  record  of  our  personnel  database.  There is a vertical
  683.  
  684.  
  685.                                       D 7
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  SHEET -- Database Part        By Chor-ming Lung               November 1, 1989
  696.  
  697.  
  698.           slider which we can use to move from  record to  record. The last
  699.           line shows  how many records in our database and what the current
  700.           record number is.
  701.  
  702.           Input record:
  703.           Input record
  704.           ____________
  705.  
  706.                If you move your mouse cursor to the box Query and press the
  707.                                                         Query
  708.           left button,  you will  see that the title is Query form now, and
  709.                                                         Query form
  710.           the contents of the first three boxes change to Main and Find. If
  711.                                                           Main     Find
  712.           you click  on the  Find box, the title changes to Find record and
  713.                              Find                           Find record
  714.           the boxes change to Main and Query. If you click on the Main box,
  715.                               Main     Query                      Main
  716.           you will get back to Input record. If you click on the Query box,
  717.                                Input record                      Query
  718.           you will get back to Query form.
  719.                                Query form
  720.  
  721.                Let us go back  to the  Input record  mode. If  the title on
  722.                                        Input record
  723.           your  dialog  box  is  not  showing  Input  record, you can press
  724.                                                Input  record
  725.           function key F1 a few  times  to  switch  back  to  Input record.
  726.                                                               Input record
  727.           Pressing function  key F1  is equivalent to clicking on the first
  728.           box. F2 is equivalent to second box...
  729.  
  730.                Now we are in Input mode.  Press  the  Left  arrow  key four
  731.                              Input 
  732.           times to move the field cursor to the field Sex, and click on the
  733.           button Search. Enter the character m and press return. The record
  734.                  Search                      m
  735.           of Jones  will be displayed. If you press F3 (Next button), Lamar
  736.              Jones                                      Next          Lamar
  737.           will be shown. Keep pressing  F3,  you  will  reach  Allen  and a
  738.                                                                Allen
  739.           message "String not found" follows.
  740.  
  741.                Let us go to the first record by moving the slider bar. Move
  742.           the mouse cursor over  the date  and press  the left  button. The
  743.           field cursor  moves from  Sex to  Date Hired. If you press <Esc>,
  744.                                     Sex     Date Hired
  745.           the date content is gone. Now enter 3-4-82  and press  left arrow
  746.                                               3-4-82
  747.           key. The  field cursor  moves to Age. We change the age to 22 and
  748.                                            Age
  749.           press return. The field  cursor  moves  to  Salary automatically.
  750.                                                       Salary
  751.           Remeber  the  editing  direction?  The  field cursor moves to the
  752.                         editing  direction
  753.           direction of the last arrow key led to.
  754.  
  755.                To sum up: we have three  different modes:  Input, Query and
  756.                           _________________________________________________
  757.           Find and  the 9  boxes are  actually mouse buttons. Function keys
  758.           _________________________________________________________________
  759.           from F1 to F9 simulate the nine mouse buttons.
  760.           ______________________________________________
  761.                In input mode:
  762.                _____________
  763.                     Query button:
  764.                     Query          activate the query form for fancy query.
  765.                     Search button:
  766.                     Search         search for simple text
  767.                     Next button:
  768.                     Next           search using the same text from Search
  769.                                                                    Search
  770.                In query mode:
  771.                _____________
  772.                     Main button:
  773.                     Main           return to Input mode
  774.                                              Input
  775.                     Find button:
  776.                     Find           show  records  that  match  the criteria
  777.                                    defined in the query forms.
  778.                In find mode:
  779.                ____________
  780.                     Main button:
  781.                     Main           return to Input mode
  782.                                              Input
  783.                     Query button:
  784.                     Query          return to Query mode
  785.                                              Query
  786.           The data  input form  accepts date in this format: mm-dd-yy (more
  787.           on this later). The line editor works the  same way  as usual. We
  788.           can move  from field to field by pressing the arrow keys or mouse
  789.  
  790.  
  791.                                       D 8
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.  
  801.  SHEET -- Database Part        By Chor-ming Lung               November 1, 1989
  802.  
  803.  
  804.           click on the content of a field. We can move record to  record by
  805.           moving the slider bar or by pressing <Shift and Up/Down arrow>.
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.                                       D 9
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  
  866.  
  867.  
  868.  
  869.  SHEET -- Database Part        By Chor-ming Lung               November 1, 1989
  870.  
  871.  
  872.           Query forms:
  873.           Query forms
  874.           ___________
  875.  
  876.                If we  press F1,  we should be in Query mode. Let us look at
  877.                                                  Query
  878.           the query forms we currently have. The first  form means  that we
  879.           want to  find those records of which the Age field is over 50 and
  880.                                                    Age
  881.           the Sex field is m. If we press  <Shift-down arrow>,  we have the
  882.               Sex
  883.           second form.  It means  Sex is  f and  Salary is  over 40000. The
  884.                                   Sex            Salary
  885.           combined effect is:
  886.                find all the records of which
  887.                     (Age>50 and Sex is m) or (Sex is f and Salary>40000)
  888.                      Age        Sex           Sex          Salary
  889.  
  890.           Find records:
  891.           Find records
  892.           ____________
  893.  
  894.                Let us press F2 to go to the Find mode. The record  shown is
  895.                                             Find
  896.           Francis. The  rest are  Farley and Allen. They match the criteria
  897.           Francis                 Farley     Allen
  898.           in our query forms.
  899.  
  900.                For fun, you can change the query forms and see the result.
  901.  
  902.           DB_INPUT arguments:
  903.           DB_INPUT arguments
  904.           __________________
  905.                DB_INPUT database, display, query, "relation list"
  906.  
  907.           In our example (cell G16),
  908.                DB_INPUT A1..E11,T1..W7,L2..P10,"1,2,3,5,4"
  909.  
  910.                Database:
  911.                _________
  912.                     A1..E11 is the area which hold our personnel database.
  913.  
  914.                   NOTE:
  915.                   NOTE   DB_INPUT determines  the maximum  number of record
  916.                          by the  number of continuous non-empty rows on the
  917.                          database. If the database  is  A1..E1000,  it will
  918.                          still say  that the  maximum number is 10, because
  919.                          the row A12..E12 is empty. If you use a larger row
  920.                          number on  your database, you can add more records
  921.                          to your  database  without  having  to  modify the
  922.                          argument from time to time.
  923.  
  924.                Display:
  925.                _______
  926.                     The following shows cells T1..W7.
  927.                         T                 U             V      W      
  928.                         ________________________________________
  929.                  1 
  930.                  2  Last Name:
  931.                     Last Name
  932.                  3 
  933.                  4 Date Hired:                         Age:
  934.                    Date Hired                          Age
  935.                  5 
  936.                  6     Salary:                         Sex:
  937.                        Salary                          Sex
  938.                  7 
  939.                     DB_INPUT scans  the display area from left to right and
  940.                top to bottom. If it finds  a  cell  is  non-empty,  it will
  941.                match the cell to the field defines in the relation list. In
  942.                                                           relation list
  943.                                                           _____________
  944.                the above example, Last Name maps to field 1, Date  Hired to
  945.                                   Last Name                  Date  Hired
  946.                field 2,  Age to field 3, Salary to field 5 and Sex to field
  947.                          Age             Salary                Sex
  948.                4. The column widths of U  and  W  confine  the  line editor
  949.                                        U       W
  950.  
  951.  
  952.                                      D 10
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  SHEET -- Database Part        By Chor-ming Lung               November 1, 1989
  963.  
  964.  
  965.                widths.
  966.  
  967.                Query:
  968.                _____
  969.                     L2..P10 is  our criteria range. Here is the list of our
  970.                criteria range:
  971.                        L        M        N        O        P       
  972.                  2 L:Name   Date HireAge      Sex      Salary
  973.                  3                   >50      m
  974.                  4                            f        >40000
  975.                   NOTE:
  976.                   NOTE   The query range  is  L2..P10,  DB_INPUT eliminates
  977.                          empty  rows  from  the  query  range to create the
  978.                          actual criteria range for query.
  979.  
  980.                Relation list:
  981.                _____________
  982.                     The relation list helps  DB_INPUT users  to create free
  983.                forms easily.  You can  design your  input form  in an order
  984.                different from the fields defined on  the database. DB_INPUT
  985.                will  use  the  minimal  number  between  non-empty cells in
  986.                display and relation list. For example,  if you  have 5 non-
  987.                empty cells  in your  display and 6 numbers in your relation
  988.                list, then DB_INPUT takes the first 5 as your relation list.
  989.                If you have 10 non-empty cells in your display and 5 numbers
  990.                in you relation list, then DB_INPUT  scans only  the first 5
  991.                non-empty  cells  from  the  display. The rest cells will be
  992.                displayed but have not effect in editing. 
  993.  
  994.           DB_INPUT entry:
  995.           DB_INPUT entry
  996.           ______________
  997.                DB_INPUT accepts the following formats of data:
  998.                   - text string.
  999.                   - date number. The format of the  date number  is defined
  1000.                     in date  string Form. It is Defaults dialog (to get the
  1001.                                     Form        Defaults
  1002.                     Default dialog, you should  select  menu  item Defaults
  1003.                     Default                                        Defaults
  1004.                     under  menu  title  Sheet).  NOTE: the function DATE is
  1005.                                         Sheet    NOTE
  1006.                     hard-coded to read date in the sequence of  month, day,
  1007.                     and year. If you change the date string Date1, Date2 or
  1008.                                                             Date1  Date2
  1009.                     Date3,  they  just  change   the  appearance   of  your
  1010.                     Date3
  1011.                     spreadsheet  display.  They  will  not change the input
  1012.                     sequence of the DATE function. That  is why  some users
  1013.                     from England  saying that  the new date format does not
  1014.                     work. However, DB_INPUT reads date in the sequence date
  1015.                     string Form  defined. So, if you change the date string
  1016.                            Form
  1017.                     Form to dd-mm-yy, then Oct 26th, 1989 should be entered
  1018.                     Form
  1019.                     26-10-89.
  1020.                     26-10-89
  1021.                   - numeric number.
  1022.  
  1023.                DB_INPUT will not accept formula at this moment, but you can
  1024.           enter formula in your query forms.
  1025.  
  1026.              NOTE1:
  1027.              NOTE1  the criteria  uses  the  standard  method  to calculate
  1028.                     result. If  you want  to find the persons who are hired
  1029.                     before  March  1st,83.  You  must  enter   the  formula
  1030.                     <date(3,1,83), but not <3-1-83.
  1031.                     <date(3,1,83)          <3-1-83
  1032.                                    _______
  1033.              NOTE2:
  1034.              NOTE2  You must  provide a  sample record for DB_INPUT to know
  1035.  
  1036.  
  1037.                                      D 11
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  SHEET -- Database Part        By Chor-ming Lung               November 1, 1989
  1048.  
  1049.  
  1050.                     what kind of entry the field is. Otherwise, all entries
  1051.                     are treated as text string. So, you must enter at least
  1052.                     one record in your  database and  reformat them  to the
  1053.                     desired  format.  Once  you  get it done, DB_INPUT have
  1054.                     enough idea to treat each field fairly.
  1055.  
  1056.           BUTTON
  1057.           BUTTON
  1058.                Syntax:
  1059.                     BUTTON name$, cell
  1060.  
  1061.                Description:
  1062.                     Do you remember the 6  empty  buttons  in  our DB_INPUT
  1063.                                                                    DB_INPUT
  1064.                dialog?  They  are  user-defined  buttons. Each user-defined
  1065.                button has a name and a subroutine that  is called  when the
  1066.                user-defined  button  is  selected.  Up  to 6 buttons can be
  1067.                defined. Only the first  8 characters  of the  name$ will be
  1068.                displayed on the mouse buttons.
  1069.  
  1070.                Example:
  1071.                     Instead  of  running  from  cell  L11,  we  can run our
  1072.                program on L14. L14 has the BASIC statements:
  1073.                     ! BUTTON "Rec #",K16: GOTO L11
  1074.                     ! BUTTON "Rec #",K16: GOTO L11
  1075.  
  1076.                L16: ! MESSAGE "Record number:|  "+STR$(CUR_REC)
  1077.                     ! MESSAGE "Record number:|  "+STR$(CUR_REC)
  1078.                L17:
  1079.                     ! RETURN
  1080.                     ! RETURN
  1081.  
  1082.                CUR_REC is the function  which  returns  the  current record
  1083.                CUR_REC
  1084.                number in  our DB_INPUT. It is a must to end your subroutine
  1085.                with RETURN.
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.                                      D 12
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  SHEET -- Database Part        By Chor-ming Lung               November 1, 1989
  1123.  
  1124.  
  1125.      Phone Book II:
  1126.      _____________
  1127.           It is time to write a database program  using our  fancy DB_INPUT
  1128.      command. Do  you remember the address book? We are going to create our
  1129.      address book database. Here is the field names of our database:
  1130.  
  1131.           Name   Street   City   State   Zip   Phone number
  1132.           _________________________________________________
  1133.  
  1134.      Column A holds field  Name, B  Street, C  City, D  State, E  Zip and F
  1135.                            Name     Street     City     State     Zip
  1136.      Phone number.  I have  reserved the  first record to be the sender. If
  1137.      Phone number
  1138.      you want to print your name  and the  receiver's name  on the envelop,
  1139.      you should  change the record of mine to yours. For the time being, we
  1140.      just do nothing to our database.
  1141.  
  1142.           Let us look at our phone book program. It starts from cell IA1.
  1143.  
  1144.          IA1    :'Phone book II
  1145.          IA2    :\-
  1146.          IA3    :! BUTTON "Dial",IB1
  1147.          IA4    :! BUTTON "Envelop",IB10
  1148.          IA5    :! ERASE IE2..IJ10
  1149.          IA6    :! DB_INPUT A1..F1000,IC2..ID10,IE1..IJ10,"1,2,3,4,5,6"
  1150.          IA7    :! END 
  1151.  
  1152.      SHEET BASIC will skip text string and starts  its execution  from cell
  1153.      IA3.
  1154.  
  1155.      IA3, IA4  creates 2  user-defined buttons on our Input form. The first
  1156.                button is called "Dial" and the second one  is "Envelop". If
  1157.                the "Dial"  button is  selected, subroutine  starts from IB1
  1158.                will be called. If "Envelop" button  is selected, subroutine
  1159.                in IB10 will be called.
  1160.      IA5       It is  not really  necessary. It clears up previous criteria
  1161.                we make.
  1162.      IA6       Our database control command. Its database  is in A1..F1000.
  1163.                We use  F1000 because  we do  not want  to change the ending
  1164.                cell from time to  time. Our  display area  is in IC2..ID10.
  1165.                Our relation list shows that the display cells are stored in
  1166.                the same order as our fields. IE1..IJ10 is our query range.
  1167.      IA7       End of our program.
  1168.  
  1169.           Let us look at our dialing routine
  1170.  
  1171.          IB1    :'Dial phone Number
  1172.          IB2    :\-
  1173.          IB3    :! REDIRECT  TO "aux:"
  1174.          IB4    :! PRINT "ATDT";F1[0, CUR_REC]$
  1175.          IB5    :! REDIRECT  TO "con:"
  1176.          IB6    :! RETURN 
  1177.  
  1178.      IB3       Change the direction of  all  subsequent  PRINT  commands to
  1179.                "AUX:" -- serial port.
  1180.      IB4       ATDT  means  (ATtension  Dial  Tone).  F1 is our Field which
  1181.                holds the phone number.  CUR_REC is  a function  which works
  1182.  
  1183.  
  1184.                                      D 13
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  SHEET -- Database Part        By Chor-ming Lung               November 1, 1989
  1195.  
  1196.  
  1197.                with DB_INPUT  only. It  returns the position of the current
  1198.                record. If CUR_REC is  3,  F1[0,3]  means  cell  F4.  Do not
  1199.                forget to  add $ to print the string on cell F4. If no $, it
  1200.                               $                                       $
  1201.                will print the value on the cell. It is 0 for text string.
  1202.      IB5       Change the direction of PRINT commands back to console.
  1203.           Let us look at our envelop printing routine
  1204.  
  1205.          IB10   :'Print address on envelop
  1206.          IB11   :\-
  1207.          IB12   :! REDIRECT  TO "prn:"
  1208.          IB13   :!x=2:t=1: GOSUB IB20
  1209.          IB14   :!x=32:t= CUR_REC: GOSUB IB20
  1210.          IB15   :! PRINT  CHR$(12)
  1211.          IB16   :! REDIRECT  TO "con:"
  1212.          IB17   :! RETURN 
  1213.  
  1214.      IB12      Change the direction of PRINT to "prn:" -- printer.
  1215.      IB13      x and  t are  variables for  subroutine IB20.  x changes the
  1216.                print-head position  to x  and t  holds the record number we
  1217.                want to print. Parameter passing is not implemented yet. So,
  1218.                we  use  global  variables  to pass parameters. We print the
  1219.                first record (the sender address).
  1220.      IB14      Print the current record.
  1221.      IB15      Form feed.
  1222.      IB16      Change the direction of PRINT comamnds back to console.
  1223.  
  1224.  
  1225.          IB20   :'Print Address
  1226.          IB21   :\-
  1227.          IB22   :! ERASE IM2..IM8
  1228.          IB23   :!IM2$=A1[0,t]$
  1229.          IB24   :!i=1:p=1:temp$=B1[0,t]$
  1230.          IB25   :! LOOP 
  1231.          IB26   :!c= POS(";",temp$,p)
  1232.          IB27   :! EXIT  IF c=0
  1233.          IB28   :!IM2[0,i]$= MID$(temp$,p,c-p):p=c+1:i=i+1
  1234.          IB29   :! ENDLOOP 
  1235.          IB30   :!IM2[0,i]$= MID$(temp$,p,100):i=i+1
  1236.          IB31   :!IM2[0,i]$=C1[0,t]$+", "+D1[0,t]$+" "+E1[0,t]$
  1237.          IB32   :! PRINT_BLOCK IM1..IM8,x,x+40
  1238.          IB33   :! RETURN 
  1239.  
  1240.      IB22      Erase  cells  from  IM2  to  IM8.  This  block  is  used for
  1241.                temporarily storage.
  1242.      IB23      IM2 holds  the name of the record being printed. temp$ holds
  1243.                the Street. NOTE: The street part may contain  more than one
  1244.                line. It is true for country other than U.S.A.
  1245.      IB24..IB30The Street  field recognizes  semicolon as a line separator.
  1246.                The routine in IB24..IB28 separates the lines and stores its
  1247.                result in IM3 down.
  1248.      IB31      This statement combines City, State Zip in one line.
  1249.                                        City, State Zip
  1250.      IB32      Print  cells  from  IM1..IM8.  The  print-head  starts  from
  1251.                position x up to 40 characters.
  1252.  
  1253.  
  1254.                                      D 14
  1255.  
  1256.  
  1257.  
  1258.